package main

import (
	"net/http"
	"log"
	"time"
	"fmt"
)

func cookie_demo(w http.ResponseWriter,r *http.Request){
	 r.ParseForm()
	 if r.Form["debug"] != nil{
		 expire := time.Now()
		 expire = expire.AddDate(1,0,0)
		 cookie := http.Cookie{Name:"name",Value:"zhangsan",Expires:expire}
		 http.SetCookie(w,&cookie)

	 }else{
		 for _,cookie := range r.Cookies(){
			 fmt.Fprint(w,cookie.Name)
		 }
		 //cookie,_ := r.Cookie("username")
		 //fmt.Fprint(w,cookie)
	 }
}

func main()  {
	//http.HandleFunc("/",hello)
	http.HandleFunc("/cookie",cookie_demo)
	err := http.ListenAndServe(":9090",nil)
	if err != nil{
		log.Fatal("ListenAndServer",err)
	}
}